const router = require('express').Router()
const M = require('kobako-maybe')
const U = require('../../utils')
const Food = require('../../models/food')

router.param('id',(req,res,next,id) => {
  if(id == null){
    res.json(U.Err('必须提供菜品id'))
    return
  }
  if(isNaN(id)){
    res.json(U.Err('请提供合法的id'))
    return
  }
  req.food_id = id
  next()
})

router.route('/:id')
  .get((req,res) => {
    res.json(U.Ok(Food.get(req.food_id)))
  })

module.exports = router